package br.com.salao.model;

import java.util.Date;
import java.util.List;
import java.util.Properties;

import javax.naming.Context;
import javax.naming.InitialContext;
import javax.rmi.PortableRemoteObject;

import org.apache.log4j.Logger;

import br.com.salao.entity.DateBusy;
import br.com.salao.session.DateBusyBase;
import br.com.salao.util.Utils;

public class DateBusyModel {
	
	/**
	 * @author Adriana Del Nero  
	 */
	
	private Logger logger =  Logger.getLogger(DateBusyModel.class.getName());

	public List<DateBusy> buscarDatasFechadasPorEstab(int idEstabelecimento){	
		try{
			DateBusyBase dateBusyBase  = getBean();
			return dateBusyBase.buscarDateBusyPorEstabelecimento(idEstabelecimento);
		} catch (Exception e) {

			StringBuffer sb = new StringBuffer();
			sb.append(e.getStackTrace());
			logger.debug(sb.toString());

			return null;
		}
	}

	public DateBusy inserir(DateBusy dateBusy){
		try{
			DateBusyBase dateBusyBase  = getBean();
			return dateBusyBase.inserir(dateBusy);
		} catch (Exception e) {

			StringBuffer sb = new StringBuffer();
			sb.append(e.getStackTrace());
			logger.debug(sb.toString());

			return null;
		}
	}

	public List<DateBusy> buscarDateBusyPorEstabelecimentoEData(int idEstabelecimento, Date dataFechada){
		try{
			DateBusyBase dateBusyBase  = getBean();
			return dateBusyBase.buscarDateBusyPorEstabelecimentoEData(idEstabelecimento, dataFechada);
		} catch (Exception e) {

			StringBuffer sb = new StringBuffer();
			sb.append(e.getStackTrace());
			logger.debug(sb.toString());

			return null;
		}
	}

    public DateBusyBase getBean() throws Exception {
    	
        Properties prop = Utils.getProperties();     
        Context ctx = new InitialContext(prop); 
        Object ref = ctx.lookup(prop.getProperty("DATEBUSY_LOOKUP"));       
      
        return (DateBusyBase)PortableRemoteObject.narrow(ref, DateBusyBase.class);
    }


}
